package com.tac.se2_project2;

import java.util.ArrayList;

import com.tac.se2_project2.R;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class Edit_cat extends Activity {
	
	String[] cat = new String[5];

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
	    if(MainActivity.themes == "green")
			{
		    	setTheme(R.style.Green);
	        }
	        if(MainActivity.themes == "blue")
	        {
	        	setTheme(R.style.blue);
	        }

	        if(MainActivity.themes == "red")
	        {
	        	setTheme(R.style.red);
	        }
		
		setContentView(R.layout.activity_edit_cat);
		
		DatabaseHandler dbh = new DatabaseHandler(this);
		
		ArrayList<String> Cats = new ArrayList<String>();
		Cats = dbh.getAllCategories();
		
		setAll(Cats);
		
	}

	public void setAll(ArrayList<String> info){
		

			((EditText)findViewById(R.id.cat1)).setText(info.get(0).toCharArray(),0,info.get(0).length());
			((EditText)findViewById(R.id.cat2)).setText(info.get(1).toCharArray(),0,info.get(1).length());
			((EditText)findViewById(R.id.cat3)).setText(info.get(2).toCharArray(),0,info.get(2).length());
			((EditText)findViewById(R.id.cat4)).setText(info.get(3).toCharArray(),0,info.get(3).length());
			((EditText)findViewById(R.id.cat5)).setText(info.get(4).toCharArray(),0,info.get(4).length());

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_edit_cat, menu);
		
		
		
		return true;
	}
	
	

	public void save(View v) {
		DatabaseHandler db = new DatabaseHandler(this);
		getAll();
		db.editCategories(cat);
		
		Toast toast = Toast.makeText(getApplicationContext(), "Categories saved",5);
		toast.show();
		
		
		
		
	}
	
	public void onPause(){
		super.onPause();
	}
	
	
	public void getAll(){
		
		cat[0] = ((EditText)findViewById(R.id.cat1)).getText().toString();
		cat[1] = ((EditText)findViewById(R.id.cat2)).getText().toString();
		cat[2] =((EditText)findViewById(R.id.cat3)).getText().toString();
		cat[3] =((EditText)findViewById(R.id.cat4)).getText().toString();
		cat[4] =((EditText)findViewById(R.id.cat5)).getText().toString();
	}

}
